package prj3;

import java.util.Iterator;

import javax.naming.OperationNotSupportedException;

public class SphericalGridIterator implements Iterator {
    private SphericalGrid grid;
    private int minLatitude;
    private int maxLatitude;
    private int minLongitude;
    private int maxLongitude;
    private int nextLatitude;
    private int nextLongitude;
    
    public SphericalGridIterator(SphericalGrid grid){
        this.grid = grid;
        minLatitude = 1;
        maxLatitude = grid.maxLatitude;
        nextLatitude = minLatitude;
        minLongitude = 0;
        maxLongitude = grid.maxLongitude;
        nextLongitude = minLongitude;
    }
    
    public boolean hasNext() {
       if(nextLongitude < maxLongitude && nextLatitude <= maxLatitude){
           return true;
       }
       return false;
    }

    public Object next() {
        SphericalCell cell = grid.getCellForCoordinate(new SphericalCoordinate(grid, nextLongitude, nextLatitude));
        
        nextLongitude++;
        if(nextLongitude >= maxLongitude){
            nextLongitude = minLongitude;
            nextLatitude++;
        }
        
        return cell;
    }

    public void remove() {
        throw new RuntimeException(new OperationNotSupportedException("You cannot currently use this iterator to remove"));
    }

}
